package info.liujiachen.test.spring.security.controller;

import info.liujiachen.test.spring.security.entity.JwtUser;
import info.liujiachen.test.spring.security.service.JwtUserDetailsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    // 日志
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private JwtUserDetailsService service;

    @PreAuthorize("hasAuthority('info')")
    @GetMapping("/api/admin/user/info")
    public JwtUser info(Authentication authentication, String username) {
        return service.findUser(username);
    }

    @PreAuthorize("hasAuthority('current')")
    @GetMapping("/api/admin/user/current")
    public String current(Authentication authentication, String username) {
        return username;
    }

}
